/*
 * angularjs公共服务
 * */

App.factory('publicService', function($rootScope, $http, $compile, $timeout, path) {
	var FUNC_Object = {};    //函数对象
	
	
	//获取当前时间
	FUNC_Object.getCurrentTime = function(type){    
		var myDate = new Date();
		
		var year = myDate.getFullYear();
		var month = myDate.getMonth();
		month += 1;
		if(month<10){
			month="0"+month;
		}
		
		var day = myDate.getDate();
		if(day<10){
			day="0"+day;
		}
		
		var hour = myDate.getHours();
		if(hour<10){
			hour="0"+hour;
		}
		
		var minute = myDate.getMinutes();
		if(minute<10){
			minute="0"+minute;
		}
		
		var second = myDate.getSeconds();
		if(second<10){
			second="0"+second;
		}
		
		var time = '';
		if(type=="date"){
			time = year+"-"+month+"-"+day;
		}else if(type=="time"){
			time = hour+":"+minute+":"+second;
		}else if(type=="dateTime"){
			time = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
		}else{
			time = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
		}
		
		return time;
	};
	
	//格式化时间
	FUNC_Object.formatTime = function(type,timestamp){    
		var myDate = new Date(timestamp);
		
		var year = myDate.getFullYear();
		var month = myDate.getMonth();
		month += 1;
		if(month<10){
			month="0"+month;
		}
		
		var day = myDate.getDate();
		if(day<10){
			day="0"+day;
		}
		
		var hour = myDate.getHours();
		if(hour<10){
			hour="0"+hour;
		}
		
		var minute = myDate.getMinutes();
		if(minute<10){
			minute="0"+minute;
		}
		
		var second = myDate.getSeconds();
		if(second<10){
			second="0"+second;
		}
		
		var time = '';
		if(type=="date"){
			time = year+"-"+month+"-"+day;
		}else if(type=="time"){
			time = hour+":"+minute+":"+second;
		}else if(type=="dateTime"){
			time = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
		}else{
			time = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
		}
		
		return time;
	};
   
   	//获取时间间隔
	FUNC_Object.getTimeRange = function(startTime,endTime,returnType){ 
		var timeRange = null;	//时间间隔
		var startDate = new Date(startTime);	//开始日期
		var endDate = new Date(endTime);		//结束日期
		
		if(returnType=="day"){
			timeRange = (startDate.getTime()-endDate.getTime())/1000/60/60/24;
		}else if(returnType=="hour"){
			timeRange = (startDate.getTime()-endDate.getTime())/1000/60/60;
		}else if(returnType=="minute"){
			timeRange = (startDate.getTime()-endDate.getTime())/1000/60;
		}else if(returnType=="second"){
			timeRange = (startDate.getTime()-endDate.getTime())/1000;
		}
		
		return Math.abs(timeRange);
	}
   
   
   	//初始化时间控件(年月日，时分秒)
	FUNC_Object.initDateTime = function(containerId){    
		$("#"+containerId).kendoDateTimePicker({
 		     value: "",
 		     culture: "zh-CN",
 		     format: "yyyy-MM-dd HH:mm:ss",   //事件格式
 		     interval: 30,   				  //时间间隔
 		     timeFormat: "HH:mm" 			  //24 hours format
 		});
	};
   
   	//初始化时间控件(年月日)
	FUNC_Object.initDate = function(containerId){    
		$("#"+containerId).kendoDatePicker({
 		     value: "",
 		     culture: "zh-CN",
 		     format: "yyyy-MM-dd"    //事件格式
 		});
	};
	
	//初始化时间控件(时分秒)
	FUNC_Object.initTime1 = function(containerId){    
		$("#"+containerId).kendoTimePicker({
  		     value: "",
  		     culture: "zh-CN",
  		     format: "HH:mm:ss",   //事件格式
  		     interval: 30,   				  //时间间隔
  		     timeFormat: "HH:mm" 			  //24 hours format
  		});
   };
   
   //初始化时间控件(时分)
	FUNC_Object.initTime2 = function(containerId){    
		$("#"+containerId).kendoTimePicker({
 		     value: "",
 		     culture: "zh-CN",
 		     format: "HH:mm",   //时间格式
 		     interval: 30,   				  //时间间隔
 		     timeFormat: "HH:mm" 			  //24 hours format
 		});
	};
	
	//去除首尾空格
	FUNC_Object.trim = function(str){
		var rule = /(^\s*)|(\s*$)/g;
		return str.replace(rule, "");
	}
	
	//去除所有空格
	FUNC_Object.trimAll = function(str){
		var rule = /\s+/g;
		return str.replace(rule, "");
	}

	//验证手机号
	FUNC_Object.checkPhoneNumber = function(value){
		var phoneStr = /^1[3|4|5|7|8]\d{9}$/; 
		if(phoneStr.test(value)){
			return true;
		}else{
			return false;
		}
	}
	
	//验证固定电话
	FUNC_Object.checkTellNumber = function(value){
		var tellStr = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,9})+(\-[0-9]{1,4})?$/; 
		if(tellStr.test(value)){
			return true;
		}else{
			return false;
		}
	}
	
	//验证邮箱
	FUNC_Object.checkMailbox = function(value){
		var mailboxStr = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/; 
		//var mailboxStr = /^[A-Za-zd]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;  
		if(mailboxStr.test(value)){
			return true;
		}else{
			return false;
		}
	}
	
	//验证是否包含汉字
	FUNC_Object.checkIsContainChinese = function(value){
		var str = /.*[\u4e00-\u9fa5]+.*$/;  
		if(str.test(value)){
			return true;
		}else{
			return false;
		}
	}
	
	//验证是否是正整数
	FUNC_Object.checkIsUpNumber = function(value){
		var str = /^[0-9]*[1-9][0-9]*$/;  
		if(str.test(value)){
			return true;
		}else{
			return false;
		}
	}
	
	//验证是否是浮点数
	FUNC_Object.checkIsFloat = function(value){
		var str = /^(- \\d+)(\\.\\d+) $/;  
		if(str.test(value)){
			return true;
		}else{
			return false;
		}
	}
	
	//获取指定长度的随机数字字母字符串
	FUNC_Object.getRandomStr = function(length){
		var str = "";
	    for( ; str.length < len; str  += Math.random().toString(36).substr(2));
	    return  str.substr(0, len);
	}
	
	//验证两个时间
	FUNC_Object.checkTwoTime = function(startTime,endTime){
		if(startTime<=endTime){
			return true;
		}else{
			return false;
		}
	}
	
	//验证两个时间段是否有交集
	FUNC_Object.checkTwoTimeRangeIsCross = function(params){
		if((params.start_1<=params.end_1 && params.start_2<=params.end_2 && (params.end_1<=params.start_2 || params.end_2<=params.start_1))){
			return true;
		}else{
			return false;
		}
	}
	
	//根据样式全选
	FUNC_Object.chooseAllByClassName = function(className,isAll){
		var checkBoxArr = $("."+className);
		
		$.each(checkBoxArr, function(index, OneObj){
			if(isAll){
				OneObj.checked = true;
			}else{
				OneObj.checked = false;
			}
		});
	}
	
	//根据样式获取选中的值
	FUNC_Object.getChooseValueByClassName = function(className){
		var idArr = new Array();
		var checkBoxArr = $("."+className);
		
		$.each(checkBoxArr, function(index, OneObj){
			var isChoose = OneObj.checked;
			if(isChoose){
				var value = OneObj.value;
				if(value){
					idArr.push(value);
				}
			}
		});
		
		return idArr;
	}
	
	//根据样式获取选中的值
	FUNC_Object.getDataFromArray = function(dataList,key,value){
		var result = {};
		
		$.each(dataList, function(index, OneObj){
			if(OneObj[key] && OneObj[key]==value){
				result = OneObj;
				return false;
			}
		});
		
		return result;
	}
	
	//某一元素是否存在当前数组
	FUNC_Object.isExitInArray = function(dataArr,key,value){
		var exit = false;
		
		$.each(dataArr, function(index, OneObj){
			if(key){
				if(OneObj[key]==value){
					exit = true;
					return false;
				}
			}else{
				if(OneObj==value){
					exit = true;
					return false;
				}
			}
		});
		
		return exit;
	}
	
	//某一元素是否存在当前数组
	FUNC_Object.getMaxAndMinFromArray = function(dataArr){
		return {
		       max:Math.max.apply(null,dataArr.join(',').split(',')),
		       min:Math.min.apply(null,dataArr.join(',').split(','))
		    }
	}
	
	//初始化《下拉列表》
	FUNC_Object.initDropDownList = function(paramObj){
		$("#"+paramObj.container).kendoDropDownList({
			dataTextField: paramObj.text,
		    dataValueField: paramObj.value,
			dataSource: paramObj.dataSource,
			optionLabel: "请选择",
			change: function(e) {
	    	    var value = this.value();
	    	    if(paramObj.changeCallback){
	    	    	paramObj.changeCallback(value,paramObj.childrenId);
    	    	}
			}
		});
	}
	
	//初始化《可填写下拉列表》
	FUNC_Object.initComboBox = function(paramObj){
		$("#"+paramObj.container).kendoComboBox({
			dataTextField: paramObj.text,
		    dataValueField: paramObj.value,
		    placeholder: paramObj.placeholder,
		    filter: "contains",
			dataSource: paramObj.dataSource,
			change: function(e) {
	    	    var value = this.value();
	    	    if(paramObj.changeCallback){
	    	    	paramObj.changeCallback(value);
    	    	}
			}
		});
	}
	
	//初始化《多选框》
	FUNC_Object.initMultiSelect = function(paramObj){
		$("#"+paramObj.container).kendoMultiSelect({
			dataTextField: paramObj.text,
		    dataValueField: paramObj.value,
		    placeholder: paramObj.placeholder,
		    filter: "contains",
			dataSource: paramObj.dataSource,
			change: function(e) {
	    	    var value = this.value();
	    	    if(paramObj.changeCallback){
	    	    	paramObj.changeCallback(value);
    	    	}
			}
		});
	}
	
	//初始化《树形视图》
	FUNC_Object.initTreeView = function(paramObj){
		$("#"+paramObj.container).kendoTreeView({
			  animation: false,
			  checkboxes: {
				  checkChildren: true,
				  template: function(e){
					  if(e.items){	//父级
						  return '<span></span>';
					  }else{	//子集
						  return '<input type="checkbox" value="'+e.id+'"/>';
					  }
				  }
			  },
			  dataTextField: paramObj.text,
			  dataSource: paramObj.dataSource
		});
	}

	/******************************************省---市---区（三级联动）【begin】******************************************/
	//type:1	 区单选
	//type:2	 区多选
	
   //初始化省
   FUNC_Object.initProvince = function(type){
		$("#province").kendoComboBox({
		    dataTextField: "name",
		    dataValueField: "code",
		    placeholder: "省",
		    filter: "contains",
		    dataSource: {
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path+"/server/province",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						return d.result;
					}
				},
	      },
	      change: function(e) {
	    	    var value = this.value();
	    	    if(!isNaN(Number(value))){
	    	    	FUNC_Object.getCityData(type,value);
	    	    }
	      }
		});
	};
   
	//获取市数据
	FUNC_Object.getCityData = function(type,provinceCode,defaultVal){
		$http({
			   url: path+"/server/city/"+provinceCode,
			   method: 'GET'
		}).success(function(data){
			FUNC_Object.initCity(type,data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化市
	FUNC_Object.initCity = function(type,cityData,defaultVal,changeCallback,isAllArea){
		if(cityData){
			var plugObj_city = $("#city").data("kendoComboBox");
			plugObj_city.value("");
			plugObj_city.setDataSource(cityData);
			if(defaultVal){
				plugObj_city.value(defaultVal);
			}
			
			//区（值清空）
			var plugObj_area = null;
			if(type==1){		//区（单选）
				plugObj_area = $("#area").data("kendoComboBox");
			}else if(type==2){	//区（多选）
				plugObj_area = $("#area").data("kendoMultiSelect");
			}
			plugObj_area.value("");
			plugObj_area.setDataSource([]);
		}else{
			$("#city").kendoComboBox({
			    dataTextField: "name",
			    dataValueField: "code",
			    placeholder: "市",
			    filter: "contains",
			    dataSource: [],
			    change: function(e) {
		    	    var value = this.value();
		    	    if(!isNaN(Number(value))){
		    	    	FUNC_Object.getAreaData(type,value,null,isAllArea);
		    	    	if(changeCallback){
		    	    		changeCallback(value);
		    	    	}
		    	    }
			    }
			});
		}
	}
	
	//获取区数据
	FUNC_Object.getAreaData = function(type,cityCode,defaultVal,isAllArea){
		$http({
			   url: path+"/server/county/"+cityCode,
			   method: 'GET'
		}).success(function(data){
			if(isAllArea){
				var allArea = {code:cityCode,name:"全城"};  
				data.result.unshift(allArea);
			}
			FUNC_Object.initArea(type,data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};

	//初始化区
	FUNC_Object.initArea = function(type,areaData,defaultVal,changeCallback){
		if(areaData){
			var plugObj_area = null;
			if(type==1){		//区（单选）
				plugObj_area = $("#area").data("kendoComboBox");
			}else if(type==2){	//区（多选）
				plugObj_area = $("#area").data("kendoMultiSelect");
			}
			
			plugObj_area.value("");
			plugObj_area.setDataSource(areaData);
			if(defaultVal){
				plugObj_area.value(defaultVal);
			}
		}else{
			if(type==1){		//区（单选）
				$("#area").kendoComboBox({
      				  dataTextField: "name",
      				  dataValueField: "code",
      				  placeholder: "区",
      				  filter: "contains",
      				  dataSource: [],
      				  change: function(e) {
    			    	if(this.dataItem()){
    			    		var value = this.dataItem().code;
    			    		if(changeCallback){
    		    	    		changeCallback(value);
    		    	    	}
    			    	}
      				  }
      			});
			}else if(type==2){	//区（多选）
				$("#area").kendoMultiSelect({
      				  dataTextField: "name",
      				  dataValueField: "code",
      				  placeholder: "区",
      				  filter: "contains",
      				  dataSource: []
      			});
			}
		}
	};
	/******************************************省---市---区（三级联动）【end】******************************************/
	
	/******************************************分类---系列（二级联动）【begin】******************************************/
	
   //初始化【产品分类】
   FUNC_Object.initProductClass = function(containerId_1,containerId_2){
		$("#"+containerId_1).kendoDropDownList({
		    dataTextField: "name",
		    dataValueField: "id",
		    optionLabel: "请选择",
		    dataSource: {
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path+"/server/querybrandclassify/-1",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						return d.result;
					}
				},
	      },
	      change: function(e) {
	    	    var value = this.value();
	    	    if(value && value!="" && !isNaN(Number(value))){
	    	    	FUNC_Object.getProductSeriesData(containerId_2,value);
	    	    }else{
	    	    	var plugObj_series = $("#"+containerId_2).data("kendoDropDownList");
	    			plugObj_series.value("");
	    			plugObj_series.setDataSource([]);
	    	    }
	      }
		});
	};	
	
	//获取产品系列数据
	FUNC_Object.getProductSeriesData = function(containerId_2,classId,defaultVal){
		$http({
			   url: path+"/server/querybrandclassify/"+classId,
			   method: 'GET'
		}).success(function(data){
			FUNC_Object.initProductSeries(containerId_2,data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化【产品系列】
	FUNC_Object.initProductSeries = function(containerId_2,seriesData,defaultVal){
		if(seriesData){
			var plugObj_series = $("#"+containerId_2).data("kendoDropDownList");
			plugObj_series.value("");
			plugObj_series.setDataSource(seriesData);
			if(defaultVal){
				plugObj_series.value(defaultVal);
			}
		}else{
			$("#"+containerId_2).kendoDropDownList({
				dataTextField: "name",
			    dataValueField: "id",
			    optionLabel: "请选择",
			    dataSource: []
			});
		}
	}	
	
	
	
	
	
	
	/******************************************分类---系列（二级联动）【end】******************************************/
	//上传文件（单个）
	FUNC_Object.uploadFile = function(containerId,fileUrlId,limitParam){
		$("#"+containerId).kendoUpload({
	        async: {
	            saveUrl: path+"/common/updoadExcelFile"
	        },
	     	multiple: false,      //多选
	      	showFileList: false,  //显示文件列表
	        localization: {
	              select: "请选择文件",
	              cancel: "取消",
	              remove: "移除",  //autoUpload: false
	              retry: "刷新",
	              headerStatusUploading: "上传...",
	              headerStatusUploaded: "上传成功",
	              statusUploading: "loading",
	              statusUploaded: "success",
	              statusFailed: "failed",
	              uploadSelectedFiles: "上传选中的文件",   //autoUpload: false
	        },
	        success: function(e){
	        	var url = e.response.result;   //图片路径
	        	if(url){
	        		$('#'+fileUrlId).val(url);
	        	}
		    },
	        error: function(e){
	        	//alert('失败！');
	        },
	        remove: function(e){
	        	//alert('移除！');
	        },
	        select: function(e){	//选择
	        	var file = e.files[0];
	        	if(limitParam){
	        		if(limitParam.fileSize && file.size>(limitParam.fileSize*1024)){
		        		alert("上传文件的大小请限制在【"+limitParam.fileSize+"Kb】以内！");
		        		e.preventDefault();
		        		return;
		        	}
	        		if(limitParam.format && limitParam.format.indexOf(file.extension.substr(1,file.extension.length).toLowerCase())==-1){
		        		alert("上传文件仅支持【"+limitParam.format+"】格式！");
		        		e.preventDefault();
		        		return;
		        	}
	        	}
	        }
	    });
	};
	//上传图片（单个）
	FUNC_Object.uploadImage = function(containerId,imgId,imgUrlId,limitParam){
		$("#"+containerId).kendoUpload({
	        async: {
	            saveUrl: path+"/common/updoad"
	        },
	     	multiple: false,      //多选
	      	showFileList: false,  //显示文件列表
	        localization: {
	              select: "请上传图片",
	              cancel: "取消",
	              remove: "移除",  //autoUpload: false
	              retry: "刷新",
	              headerStatusUploading: "上传...",
	              headerStatusUploaded: "上传成功",
	              statusUploading: "loading",
	              statusUploaded: "success",
	              statusFailed: "failed",
	              uploadSelectedFiles: "上传选中的文件",   //autoUpload: false
	        },
	        success: function(e){
	        	var url = e.response.result;   //图片路径
	        	FUNC_Object.showUploadImage(imgId,imgUrlId,url);
		    },
	        error: function(e){
	        	//alert('失败！');
	        },
	        remove: function(e){
	        	//alert('移除！');
	        },
	        select: function(e){	//选择
	        	var image = e.files[0];
	        	if(limitParam){
	        		if(limitParam.imageSize && image.size>(limitParam.imageSize*1024)){
		        		alert("上传图片的大小请限制在【"+limitParam.imageSize+"Kb】以内！");
		        		e.preventDefault();
		        		return;
		        	}
	        		if(limitParam.format && limitParam.format.indexOf(image.extension.substr(1,image.extension.length).toLowerCase())==-1){
		        		alert("上传图片仅支持【"+limitParam.format+"】格式！");
		        		e.preventDefault();
		        		return;
		        	}
	        	}
	        }
	    });
	};
	
	//上传图片（多个）
	FUNC_Object.uploadMultipleImage = function(containerId,imgId,imgUrlId){
		$("#"+containerId).kendoUpload({
	        async: {
	            saveUrl: path+"/common/uploads",
	            batch: true
	        },
	     	multiple: true,      //多选
	      	showFileList: false,  //显示文件列表
	        localization: {
	              select: "请上传图片",
	              cancel: "取消",
	              remove: "移除",  //autoUpload: false
	              retry: "刷新",
	              headerStatusUploading: "上传...",
	              headerStatusUploaded: "上传成功",
	              statusUploading: "loading",
	              statusUploaded: "success",
	              statusFailed: "failed",
	              uploadSelectedFiles: "上传选中的文件",   //autoUpload: false
	        },
	        success: function(e){
	        	var url = e.response.result;   //图片路径
	        	//FUNC_Object.showUploadImage(imgId,imgUrlId,url);
		    },
	        error: function(e){
	        	//alert('失败！');
	        },
	        remove: function(e){
	        	//alert('移除！');
	        }
	    });
	};
	
	//反显图片并赋值
	FUNC_Object.showUploadImage = function(imgId,imgUrlId,url){
		if(url && url!="undefined"){
			$("#"+imgId).css({
				"background": "url('"+url+"') no-repeat",
	    	    "background-size":"100% 100%",
	    	    "background-color":"white"
	    	});
			if(imgUrlId){
				$('#'+imgUrlId).val(url);
			}
		}else{
			$("#"+imgId).css({
				"background": "url('') no-repeat"
	    	});
			$('#'+imgUrlId).val('');
		}
	};
	
	//移除图片
	FUNC_Object.removeUploadImage = function(imgId,imgUrlId){
		$("#"+imgId).removeAttr("style");
		$('#'+imgUrlId).val("");
	};
	
	//表格合并
	FUNC_Object.tableTdRowspan = function(gridName,mergeTdArr){
		var tableTrObj = $("div[kendo-grid='"+gridName+"']").children("div:eq(1)").children("table").children("tbody").children("tr");
		var trLength = $(tableTrObj).length;
		
		$.each(mergeTdArr,function(index_td,obj_td){
			var whichTd = obj_td;	//合并列
			
			var rowspanCount = 1;
			var groupTrIndex = 0;	//分组行下标
			var tdText = "";  		//合并表格内容
			var trIndex = 0;		//合并行
			
			$.each(tableTrObj,function(index,obj){
				var roleName = $(this).attr("role");
				if(roleName=="row"){	//分组标题行
					if(rowspanCount>1){
						$(tableTrObj[trIndex]).children("td:eq("+whichTd+")").attr("rowspan",rowspanCount);
						rowspanCount = 1;
						tdText = nowTdText;
						trIndex = index;
					}
					
					groupTrIndex = index;
					rowspanCount = 1;
				}else{
					var nowTdText = $(this).children("td:eq("+whichTd+")").text();   //当前行td的文本值
					
					if(index==(groupTrIndex+1)){	//分组数据【第一条记录】
						tdText = nowTdText;
						trIndex = index;
					}else{
						if(nowTdText==tdText){   
							$(this).children("td:eq("+whichTd+")").remove();
							rowspanCount ++;
							if(index==(trLength-1)){   //最后一行
								$(tableTrObj[trIndex]).children("td:eq("+whichTd+")").attr("rowspan",rowspanCount);
							}
						}else{
							$(tableTrObj[trIndex]).children("td:eq("+whichTd+")").attr("rowspan",rowspanCount);
							
							rowspanCount = 1;
							tdText = nowTdText;
							trIndex = index;
						}
					}
				}
			});
		});	
	}

	//实例化树形控件
	FUNC_Object.initZtree = function(ztreeId,dataArr,paramObj){
		var zTree = new ZtreeTool(ztreeId,paramObj);
		zTree.setParam();
		zTree.showTree(dataArr);
		
		return zTree;
	}
	
	//初始化【活动状态】
	FUNC_Object.initActivityState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
			dataSource: [
	             {
	            	value: "",
	 				text: "请选择"
	             },
	             {
	            	value: 0,
	 				text: "未开始"
	             },
	             {
	            	value: 1,
	 				text: "进行中"
	             },
	             {
	            	value: 2,
	 				text: "已结束"
	             }
            ]
		});
	}
	
	//初始化【活动显示隐藏】
	FUNC_Object.initActivityShowHidden = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
			dataSource: [
	             {
	            	value: "",
	 				text: "请选择"
	             },
	             {
	            	value: 0,
	 				text: "下架"
	             },
	             {
	            	value: 1,
	 				text: "上架"
	             }
            ]
		});
	}
	
	//初始化【审核状态】
	FUNC_Object.initCheckState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
			dataSource: [
	             {
	            	value: "",
	 				text: "请选择"
	             },
	             {
	            	value: 0,
	 				text: "待审核"
	             },
	             {
	            	value: 1,
	 				text: "审核通过"
	             },
	             {
	            	value: 2,
	 				text: "未通过"
	             }
            ]
		});
	}
	
	//初始化【卡券类型】
	FUNC_Object.initCardType = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "红包"
		             },
		             {
		            	value: 2,
		 				text: "优惠券"
		             },
		             {
		            	value: 3,
		 				text: "折扣券"
		             }
            ]
		});
	}
	
	//初始化【用户级别】
	FUNC_Object.initUserLevel = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "一级"
		             },
		             {
		            	value: 2,
		 				text: "二级"
		             },
		             {
		            	value: 3,
		 				text: "三级"
		             }
            ]
		});
	}
	
	//初始化【用户级别】二级
	FUNC_Object.initUserLevel_2 = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "一级"
		             },
		             {
		            	value: 2,
		 				text: "二级"
		             }
            ]
		});
	}
	
	//初始化【用户标签】
	FUNC_Object.initUserLabel = function(containerId){
		$("#"+containerId).kendoComboBox({
			filter: "contains",
			placeholder: "请选择",
		    dataSource: {
		          transport: {
		              read: {
		            	  type : 'GET',
		                  url: path+"/server/selectShopTag",
		                  dataType : "json"
		              }
		          }
		    }
		});
	}
	
	//初始化【账号上下架】
	FUNC_Object.initAccountUpOrDown = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "上架"
		             },
		             {
		            	value: 0,
		 				text: "下架"
		             }
            ]
		});
	}
	
	//初始化【账号状态】
	FUNC_Object.initAccountState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "开通"
		             },
		             {
		            	value: 0,
		 				text: "关闭"
		             }
            ]
		});
	}
	
	//初始化【账号状态】2
	FUNC_Object.initAccountState2 = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 1,
		 				text: "启用"
		             },
		             {
		            	value: 0,
		 				text: "停用"
		             }
            ]
		});
	}
	
	//初始化【导购状态】
	FUNC_Object.initGuiderState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					 {
						value: "",
						text: "请选择"
					 },
		             {
		            	value: 1,
		 				text: "正常"
		             },
		             {
		            	value: 0,
		 				text: "关闭"
		             }
            ]
		});
	}
	
	//初始化【导购类型】
	FUNC_Object.initGuiderType = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					 {
						value: "",
						text: "请选择"
					 },		            
		             {
		            	value: 1,
		 				text: "推广"
		             },
		             {
		            	value: 2,
		 				text: "店员"
		             },
		             {
		            	value: 3,
		 				text: "临促"
		             },
		             {
		            	value: 4,
		 				text: "小区推广"
		             }
            ]
		});
	}
	
	//初始化【任务类型】
	FUNC_Object.initTaskType = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 1,
		 				text: "销售任务"
		             },
		             {
		            	value: 2,
		 				text: "活动任务"
		             }
            ]
		});
	}
	
	//初始化【任务上下架】
	FUNC_Object.initTaskUpOrDown = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "上架"
		             },
		             {
		            	value: 0,
		 				text: "下架"
		             }
            ]
		});
	}
	
	//初始化【任务状态】
	FUNC_Object.initTaskState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: "",
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "未开始"
		             },
		             {
		            	value: 2,
		 				text: "进行中"
		             },
		             {
		            	value: 3,
		 				text: "已结束"
		             },
		             {
		            	value: 4,
		 				text: "已暂停"
		             }
            ]
		});
	}
	
	//初始化【是否新品】
	FUNC_Object.initIsNew = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					 {
						value: "",
						text: "请选择"
					 },		            
		             {
		            	value: 1,
		 				text: "是"
		             },
		             {
		            	value: 0,
		 				text: "否"
		             }
            ]
		});
	}
	
	//初始化【用户渠道】
	FUNC_Object.initUserForm = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					 {
						value: "",
						text: "请选择"
					 },		            
		             {
		            	value: 1,
		 				text: "公司分配"
		             },
		             {
		            	value: 2,
		 				text: "邀请注册"
		             }
            ]
		});
	}
	
	//初始化【消费者来源】
	FUNC_Object.initCustomerSource = function(containerId,changeCallback){
		$("#"+containerId).kendoDropDownList({
		    dataTextField: "name",
		    dataValueField: "id",
		    optionLabel: "请选择",
		    dataSource: {
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path + "/server/selectCustomerSourceList",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						var firstData = {name:"小程序",id:0};
						d.result.unshift(firstData);
						return d.result;
					}
				},
		    },
		    change: function(e) {
	    	    var value = this.value();
	    	    if(value && changeCallback){
	    	    	changeCallback(value);
	    	    }
		    }
		});
	}
	
	//初始化【用户类型】
	FUNC_Object.initUserType = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					 {
						value: "",
						text: "请选择"
					 },		            
		             {
		            	value: "新客户",
		 				text: "新客户"
		             },
		             {
		            	value: "订单客户",
		 				text: "订单客户"
		             },
		             {
		            	value: "活动客户",
		 				text: "活动客户"
		             }
            ]
		});
	}
	
	//初始化【产品状态】
	FUNC_Object.initProductState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
			dataSource: [
	             {
	            	value: "",
	 				text: "请选择"
	             },
	             {
	            	value: 0,
	 				text: "下架"
	             },
	             {
	            	value: 1,
	 				text: "上架"
	             }
            ]
		});
	}
	
	//初始化【预约状态】
	FUNC_Object.initBookingState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
			dataSource: [
			             {
			            	value: "",
			 				text: "请选择"
			             },
			             {
			            	value: 1,
			 				text: "已提交"
			             },
			             {
			            	value: 2,
			 				text: "已确认"
			             },
			             {
			            	value: 3,
			 				text: "受理中"
			             },
			             {
			            	value: 4,
			 				text: "已完成"
			             },
			             {
			            	value: 5,
			 				text: "已取消"
			             },
			             {
			            	value: 6,
			 				text: "无法受理"
			             }
			             
			             
            ]
		});
	}
	
	//初始化【订单状态】
	FUNC_Object.initOrderState = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
			dataSource: [
			             {
			            	value: "",
			 				text: "请选择"
			             },
			             {
			            	value: 1,
			 				text: "已付定金"
			             },
			             {
			            	value: 2,
			 				text: "已付全款"
			             },
			             {
			            	value: 3,
			 				text: "配送中"
			             },
			             {
			            	value: 4,
			 				text: "安装"
			             },
			             {
			            	value: 5,
			 				text: "关闭"
			             }
            ]
		});
	}
	
   //初始化用户【店铺列表】
   FUNC_Object.initUserShopList = function(containerId){
		$("#"+containerId).kendoDropDownList({
		    dataTextField: "account",
		    dataValueField: "id",
		    dataSource: {
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path + "/server/selectUserShop",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						return d.result;
					}
				},
	      }
		});
	};
//-------------------------------------------以上是叔亮,以下是郭雯-----------------------------------------------
   //将秒转换成 时间格式
   FUNC_Object.switchTime= function(shijianchuo,type){
	   var time = new Date(shijianchuo);
	   var y = time.getFullYear();
	   var m = time.getMonth()+1;
	   var d = time.getDate();
	   var h = time.getHours();
	   var mm = time.getMinutes();
	   var s = time.getSeconds();
	   if(type =='date'){   //年月日
		   return y+'-'+judgeDuration(m)+'-'+judgeDuration(d);
	   }else if(type =='time'){  //时分秒
		   return judgeDuration(h)+':'+judgeDuration(mm)+':'+judgeDuration(s);
	   }else if(type =='dateTime'){  //年月日时分秒
		   return y+'-'+judgeDuration(m)+'-'+judgeDuration(d)+' '+judgeDuration(h)+':'+judgeDuration(mm)+':'+judgeDuration(s);
	   }
	  
	};
	
	function judgeDuration(m){
		return m<10?'0'+m:m
	};
	
	
	
	//判断开始时间大于结束时间
	FUNC_Object.decideTime = function(start,end){
		var startTime =  new Date(start).getTime();  //开始时间
		var endTime =  new Date(end).getTime();      //结束时间
		if(startTime>endTime){
			return true;
		}else{
			return false;
		}
	};	
	
	
	return FUNC_Object;
	

});